//
//  EditResumeViewController.m
//  CYWFrame
//
//  Created by 于顺燊 on 2018/9/6.
//  Copyright © 2018年 Macx. All rights reserved.
//

#import "AddResumeViewController.h"
#import "UIButton+WebCache.h"
#import <Masonry.h>
#import "WSDatePickerView.h"
#import "JobCategoryInfo.h"
#import "CZHAddressPickerView.h"

@interface AddResumeViewController ()<UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate, UITextViewDelegate, UIPickerViewDelegate, UIPickerViewDataSource>

// 相册照相机
@property (nonatomic, strong) UIImagePickerController *picker;
@property (nonatomic, strong) NSString *imgStr;
@property (nonatomic, strong) NSString *sexT;
@property (nonatomic, strong) NSString *money;

@property (nonatomic, assign) BOOL isChangeImage;

@property (nonatomic, assign) BOOL isTeturn;

@property (nonatomic, strong) NSString *ageStr;

@property (nonatomic, strong) NSString *birthdayStr;
@property (nonatomic, strong) NSString *workDateStr;

@property (nonatomic, strong) NSString *jobCategoryStr;

/** 后台返回的职位类别数据数组 */
@property (strong, nonatomic) NSMutableArray *jobCategoryInfoArr;

@property (strong, nonatomic) NSArray *educationInfoArr;
@property (strong, nonatomic) NSArray *salaryInfoArr;
@property (strong, nonatomic) NSArray *workLifeInfoArr;

/** 当前选中的职位ID */
@property (strong, nonatomic) NSString *selectedCategoryID;

/** 当前选中数组 */
@property (strong, nonatomic) NSArray *selectedArray;

@property (nonatomic, strong) NSMutableArray *ageArr;

@end

@implementation AddResumeViewController{

	UIView          *_headBgView;
	UIButton        *_returnBtn;
	UITextField             *_jobCategoryTF;
	UITextField             *_ageTF;
	
	UIView                  *_pickerBgView;
	
	UIPickerView            *_categoryPicker;
	UIPickerView            *_salaryPicker;
	UIPickerView            *_educationPicker;
	UIPickerView            *_workLifePicker;
	
	UIPickerView            *_agePicker;
	
	UIView                  *_pickerToolbgView;
	
	UIScrollView            *_scorllView;

}

- (void)viewWillDisappear:(BOOL)animated {
	
}

- (void)willMoveToParentViewController:(UIViewController*)parent{
	[super willMoveToParentViewController:parent];
	
	if (self.isTeturn) {
		[self isReturn];
	}
}

- (void)viewDidLoad {
	[super viewDidLoad];
	
	// Do any additional setup after loading the view.
	
	//self.zf_interactivePopDisabled = YES;
	self.userInfo = GetUserDefaule(USERINFO);
	
	[self getCategory];
	
	[self createUI];
	
	[self createImgPicker];
	
}

- (void)updateUserInfo {
	 [[NetworkTool sharedTool] requestWithName:@"个人中心信息获取" URLString:APIPersonal parameters:nil method:@"GET" callBack:^(id responseObject) {
		 NSDictionary *userDict = [responseObject valueForKey:@"data"];
		 SetUserDefaule(userDict, USERINFO);
	 }];
}

- (void)getCategory {
	
	[[NetworkTool sharedTool] requestWithName:@"获取职位分类列表" URLString:APIRecruitCategoryList parameters:nil method:@"GET" callBack:^(id responseObject) {
		
		NSArray *arr = responseObject[@"data"];
		[_jobCategoryInfoArr removeAllObjects];
		for (NSDictionary *dict in arr)
		{
			JobCategoryInfo *model = [[JobCategoryInfo alloc] init];
			[model setValuesForKeysWithDictionary:dict];
			[_jobCategoryInfoArr addObject:model];
		}
		
		[_categoryPicker reloadComponent:0];
		[_categoryPicker reloadComponent:1];
		 
	}];
}


- (void)createUI {
	
	self.view.backgroundColor = UISeparatedColorRGB;
	
	_headBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64)];
	[self.view addSubview:_headBgView];
	_headBgView.backgroundColor = UIMainColorRGB;
	
	// 返回btn
	_returnBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	//[_headBgView addSubview:_returnBtn];
	[_returnBtn setImage:IMAGE(@"return") forState:UIControlStateNormal];
	[_returnBtn addTarget:self action:@selector(navLeftAction:) forControlEvents:UIControlEventTouchUpInside];
	_returnBtn.frame = CGRectMake(0, 20, 44, 44);
	[self.view addSubview:_returnBtn];
	
	UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(SW(2)-50, _returnBtn.y, 100, 50)];
	titleLabel.text = @"添加简历";
	titleLabel.textColor = kWhiteColor;
	titleLabel.textAlignment = NSTextAlignmentCenter;
	[_headBgView addSubview:titleLabel];
	
	
	_scorllView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
	[self.view addSubview:_scorllView];
	NSArray *arr = [NSArray arrayWithObjects:@"   头像", @"   姓名*", @"   性别", @"   所在城市", @"   生日", @"   期望职位*", @"   期望薪资*", @"   学历*", @"   工作经验*", @"   参加工作时间", @"   手机号码*", @"   邮箱地址*", @"   用一句话描述自己", nil];
	
	CGSize size = [LZCTools textSizeWithText:@"字数" font:kUHSystemFontWithSize(15)];
	
	for (int i = 0; i < arr.count; i++) {
		UILabel *label = [[UILabel alloc] init];
		[_scorllView addSubview:label];
		label = [self createLabel:label text:arr[i]];
		label.tag = 1+i;
	}
	
	UILabel *headPic = [self.view viewWithTag:1];
	headPic.frame = CGRectMake(0, 0, SCREEN_WIDTH, size.height+30);
	
	UIButton *headPicBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	[_scorllView addSubview:headPicBtn];
	headPicBtn.frame = CGRectMake(SCREEN_WIDTH-SW(20)-20-size.height, 5,  20+size.height,  20+size.height);
	headPicBtn.layer.cornerRadius = (20+size.height)/2;
	headPicBtn.layer.masksToBounds = YES;
	[headPicBtn sd_setImageWithURL:[self.userInfo valueForKey:@"face"] forState:UIControlStateNormal];
	self.imgStr = [self.userInfo valueForKey:@"face"];
	[headPicBtn addTarget:self action:@selector(headPicAction:) forControlEvents:UIControlEventTouchUpInside];
	headPicBtn.tag = 21;
	
	UILabel *myName = [self.view viewWithTag:2];
	myName.frame = CGRectMake(0, headPic.y+headPic.height+1, SCREEN_WIDTH, size.height+30);
	
	UITextField *myNameTF = [[UITextField alloc] initWithFrame:CGRectMake(30+size.width, 15+headPic.y+headPic.height+1, SCREEN_WIDTH-30-size.width-SW(20), size.height)];
	[_scorllView addSubview:myNameTF];
	myNameTF.textAlignment = NSTextAlignmentRight;
	myNameTF.textColor = [UIColor lightGrayColor];
	myNameTF.text = [self.userInfo valueForKey:@"nickname"];
	myNameTF.font = kUHSystemFontWithSize(15);
	myNameTF.tag = 22;
	myNameTF.delegate = self;
	
	UILabel *sex = [self.view viewWithTag:3];
	sex.frame = CGRectMake(0, myName.y+myName.height+1, SCREEN_WIDTH, size.height+30);
	
	UIButton *sexBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	[_scorllView addSubview:sexBtn];
	sexBtn.titleLabel.font = kUHSystemFontWithSize(15);
	[sexBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
	sexBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
	
	if ([[self.userInfo valueForKey:@"sex"] isEqualToString:@"1"]) {
		[sexBtn setTitle:@"男" forState:UIControlStateNormal];
		self.sexT = @"1";
	}
	else {
		[sexBtn setTitle:@"女" forState:UIControlStateNormal];
		self.sexT = @"2";
	}
	sexBtn.frame = CGRectMake(30+size.width, myName.y+myName.height+1, SCREEN_WIDTH-30-size.width-SW(20), size.height+30);
	[sexBtn addTarget:self action:@selector(sexAction:) forControlEvents:UIControlEventTouchUpInside];
	sexBtn.tag = 23;
	
	//所在城市(其实应该叫district..)
	UILabel *address = [self.view viewWithTag:4];
	address.frame = CGRectMake(0, sex.y+sex.height+1, SCREEN_WIDTH, size.height+30);
	[_scorllView addSubview:address];
	UITextField *addressTF = [[UITextField alloc] initWithFrame:CGRectMake(30+size.width, address.y+15, SCREEN_WIDTH-30-size.width-SW(20), size.height)];
	[_scorllView addSubview:addressTF];
	addressTF.textAlignment = NSTextAlignmentRight;
	addressTF.rightViewMode = UITextFieldViewModeAlways;
	addressTF.textColor = [UIColor lightGrayColor];
	addressTF.font = kUHSystemFontWithSize(15);
	addressTF.tag = 24;
	addressTF.delegate = self;
	UIImageView *imgVCity = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, size.height/2, size.height)];
	addressTF.rightView = imgVCity;
	imgVCity.image = IMAGE(@"arrow_right_grey");
	UIView *viewCity = [[UIView alloc] initWithFrame:CGRectMake(addressTF.x, addressTF.y, addressTF.width, addressTF.height)];
	[_scorllView addSubview:viewCity];
	[viewCity addActionWithblock:^{
		NSLog(@"选择所在城市");
		[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
		[CZHAddressPickerView areaPickerViewWithAreaBlock:^(NSString *province, NSString *city, NSString *area) {
			addressTF.text = [NSString stringWithFormat:@"%@%@", city, area];
		}];
	}];
	
	
	
	//出生年月
	UILabel *ageL = [self.view viewWithTag:5];
	ageL.frame = CGRectMake(0, address.y+address.height+1, SCREEN_WIDTH, size.height+30);
	
	
	UITextField *ageF = [[UITextField alloc] initWithFrame:CGRectMake(30+size.width, ageL.y, SCREEN_WIDTH-(50+size.width), size.height+30)];
	[_scorllView addSubview:ageF];
	ageF.delegate = self;
	ageF.textColor = kGrayColor;
	ageF.clearButtonMode = UITextFieldViewModeWhileEditing;
	ageF.font = kUHSystemFontWithSize(15);
	ageF.textAlignment = NSTextAlignmentRight;
	ageF.rightViewMode = UITextFieldViewModeAlways;
	ageF.tag = 25;
	UIImageView *imgV0 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, size.height/2, size.height)];
	ageF.rightView = imgV0;
	imgV0.image = IMAGE(@"arrow_right_grey");
	_ageTF = ageF;
	self.birthdayStr = @"";
	
	UIView *view0 = [[UIView alloc] initWithFrame:CGRectMake(ageF.x, ageF.y, ageF.width, ageF.height)];
	[_scorllView addSubview:view0];
	[view0 addActionWithblock:^{
		NSLog(@"选择生日");
		[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
		UITextField *tf = [self.view viewWithTag:21];
		[tf resignFirstResponder];
		UITextView *tv = [self.view viewWithTag:33];
		[tv resignFirstResponder];
		
		// 显示日期选择
		WSDatePickerView *datepicker = [[WSDatePickerView alloc] initWithDateStyle:DateStyleShowYearMonthDay CompleteBlock:^(NSDate *selectDate) {
			
			//            NSString *date = [selectDate stringWithFormat:@"yyyy-MM-dd"];
			NSString *date = [NSString stringWithFormat:@"%ld年%ld月%ld日",selectDate.year,selectDate.month,selectDate.day];
			ageF.text = date;
			self.birthdayStr = [NSString stringWithFormat:@"%ld%02ld%02ld",selectDate.year,selectDate.month,selectDate.day];
			
			// 获取系统当前 年月日
			NSDateComponents *components2 = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate date]];
			NSInteger currentDateYear = [components2 year];
			NSInteger currentDateMonth = [components2 month];
			NSInteger currentDateDay= [components2 day];
			
			// 计算年龄
			NSInteger iAge = currentDateYear - selectDate.year - 1;
			if ((currentDateMonth > selectDate.month) || (currentDateMonth == selectDate.month && currentDateDay >= selectDate.day)) {
				iAge++;
			}
			self.ageStr = [NSString stringWithFormat: @"%ld",iAge];
			
			[self pickerRemove];
		}];
		
		NSDateFormatter *minDateFormater = [[NSDateFormatter alloc] init];
		[minDateFormater setDateFormat:@"yyyy-MM-dd"];
		NSDate *scrollToDate = [minDateFormater dateFromString:@"1930-1-1"];
		datepicker.minLimitDate = scrollToDate;
		datepicker.maxLimitDate = [NSDate date];
		[datepicker show];
	}];
	
	
	// 职位
	UILabel *job = [self.view viewWithTag:6];
	job.frame = CGRectMake(0, ageL.y+ageL.height+1, SCREEN_WIDTH, size.height+30);
	
	UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(30+size.width, job.y, SCREEN_WIDTH-(50+size.width), size.height+30)];
	[_scorllView addSubview:field];
	field.delegate = self;
	field.textColor = kGrayColor;
	field.clearButtonMode = UITextFieldViewModeWhileEditing;
	field.font = kUHSystemFontWithSize(15);
	field.textAlignment = NSTextAlignmentRight;
	field.rightViewMode = UITextFieldViewModeAlways;
	UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, size.height/2, size.height)];
	field.rightView = imgV;
	field.tag = 26;
	imgV.image = IMAGE(@"arrow_right_grey");
	_jobCategoryTF = field;
	self.jobCategoryStr = field.text;
	
	UIView *view = [[UIView alloc] initWithFrame:CGRectMake(field.x, field.y, field.width, field.height)];
	[_scorllView addSubview:view];
	[view addActionWithblock:^{
		NSLog(@"选择职位");
		
		UITextField *tf = [self.view viewWithTag:21];
		[tf resignFirstResponder];
		UITextView *tv = [self.view viewWithTag:33];
		[tv resignFirstResponder];
		
		[self pickerShow:2];
		
	}];
	
	//薪资
	UILabel *salary = [self.view viewWithTag:7];
	salary.frame = CGRectMake(0, job.y+job.height+1, SCREEN_WIDTH, size.height+30);
	
	UITextField *salaryField = [[UITextField alloc] initWithFrame:CGRectMake(30+size.width, salary.y, SCREEN_WIDTH-(50+size.width), size.height+30)];
	[_scorllView addSubview:salaryField];
	salaryField.delegate = self;
	salaryField.textColor = kGrayColor;
	salaryField.clearButtonMode = UITextFieldViewModeWhileEditing;
	salaryField.font = kUHSystemFontWithSize(15);
	salaryField.textAlignment = NSTextAlignmentRight;
	salaryField.rightViewMode = UITextFieldViewModeAlways;
	salaryField.tag = 27;
	UIImageView *imgV2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, size.height/2, size.height)];
	salaryField.rightView = imgV2;
	imgV2.image = IMAGE(@"arrow_right_grey");
	
	UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(salaryField.x, salaryField.y, salaryField.width, salaryField.height)];
	[_scorllView addSubview:view2];
	[view2 addActionWithblock:^{
		NSLog(@"选择薪资");
		[self pickerShow:3];
		
	}];
	
	//学历
	UILabel *education = [self.view viewWithTag:8];
	education.frame = CGRectMake(0, salary.y+salary.height+1, SCREEN_WIDTH, size.height+30);
	
	UITextField *educationField = [[UITextField alloc] initWithFrame:CGRectMake(30+size.width, education.y, SCREEN_WIDTH-(50+size.width), size.height+30)];
	[_scorllView addSubview:educationField];
	educationField.delegate = self;
	educationField.textColor = kGrayColor;
	educationField.clearButtonMode = UITextFieldViewModeWhileEditing;
	educationField.font = kUHSystemFontWithSize(15);
	educationField.textAlignment = NSTextAlignmentRight;
	educationField.rightViewMode = UITextFieldViewModeAlways;
	educationField.tag = 28;
	UIImageView *imgV3 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, size.height/2, size.height)];
	educationField.rightView = imgV3;
	imgV3.image = IMAGE(@"arrow_right_grey");
	
	UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(educationField.x, educationField.y, educationField.width, educationField.height)];
	[_scorllView addSubview:view3];
	[view3 addActionWithblock:^{
		NSLog(@"选择学历");
		[self pickerShow:4];
		
	}];
	
	//工作年限
	UILabel *workLife = [self.view viewWithTag:9];
	workLife.frame = CGRectMake(0, education.y+education.height+1, SCREEN_WIDTH, size.height+30);
	
	UITextField *workLifeField = [[UITextField alloc] initWithFrame:CGRectMake(30+size.width, workLife.y, SCREEN_WIDTH-(50+size.width), size.height+30)];
	[_scorllView addSubview:workLifeField];
	workLifeField.delegate = self;
	workLifeField.textColor = kGrayColor;
	workLifeField.clearButtonMode = UITextFieldViewModeWhileEditing;
	workLifeField.font = kUHSystemFontWithSize(15);
	workLifeField.textAlignment = NSTextAlignmentRight;
	workLifeField.rightViewMode = UITextFieldViewModeAlways;
	workLifeField.tag = 29;
	UIImageView *imgV4 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, size.height/2, size.height)];
	workLifeField.rightView = imgV4;
	imgV4.image = IMAGE(@"arrow_right_grey");
	
	UIView *view4 = [[UIView alloc] initWithFrame:CGRectMake(workLifeField.x, workLifeField.y, workLifeField.width, workLifeField.height)];
	[_scorllView addSubview:view4];
	[view4 addActionWithblock:^{
		NSLog(@"选择工作年限");
		[self pickerShow:5];
		
	}];
	
	
	//参加工作时间
	UILabel *workDate = [self.view viewWithTag:10];
	workDate.frame = CGRectMake(0, workLife.y+workLife.height+1, SCREEN_WIDTH, size.height+30);
	
	UITextField *workDateField = [[UITextField alloc] initWithFrame:CGRectMake(30+size.width, workDate.y, SCREEN_WIDTH-(50+size.width), size.height+30)];
	[_scorllView addSubview:workDateField];
	workDateField.delegate = self;
	workDateField.textColor = kGrayColor;
	workDateField.clearButtonMode = UITextFieldViewModeWhileEditing;
	workDateField.font = kUHSystemFontWithSize(15);
	workDateField.textAlignment = NSTextAlignmentRight;
	workDateField.rightViewMode = UITextFieldViewModeAlways;
	workDateField.tag = 30;
	UIImageView *imgV5 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, size.height/2, size.height)];
	workDateField.rightView = imgV5;
	imgV5.image = IMAGE(@"arrow_right_grey");
	self.workDateStr = @"";
	
	UIView *view5 = [[UIView alloc] initWithFrame:CGRectMake(workDateField.x, workDateField.y, workDateField.width, workDateField.height)];
	[_scorllView addSubview:view5];
	[view5 addActionWithblock:^{
		NSLog(@"选择参加工作时间");
		[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
		// 显示日期选择
		WSDatePickerView *datepicker = [[WSDatePickerView alloc] initWithDateStyle:DateStyleShowYearMonthDay CompleteBlock:^(NSDate *selectDate) {
			
			//            NSString *date = [selectDate stringWithFormat:@"yyyy-MM-dd"];
			NSString *date = [NSString stringWithFormat:@"%ld年%ld月%ld日",selectDate.year,selectDate.month,selectDate.day];
			UITextField *workDateF = (UITextField *)[self.view viewWithTag:30];
			workDateF.text = date;
			self.workDateStr = [NSString stringWithFormat:@"%ld%02ld%02ld",selectDate.year,selectDate.month,selectDate.day];
			
			[self pickerRemove];
		}];
		
		NSDateFormatter *minDateFormater = [[NSDateFormatter alloc] init];
		[minDateFormater setDateFormat:@"yyyy-MM-dd"];
		NSDate *scrollToDate = [minDateFormater dateFromString:@"1930-1-1"];
		datepicker.minLimitDate = scrollToDate;
		datepicker.maxLimitDate = [NSDate date];
		[datepicker show];
	}];
	
	
	//联系方式(手机号码)
	UILabel *phone = [self.view viewWithTag:11];
	phone.frame = CGRectMake(0, workDate.y+workDate.height+1, SCREEN_WIDTH, size.height+30);
	[_scorllView addSubview:phone];
	UITextField *phoneTF = [[UITextField alloc] initWithFrame:CGRectMake(30+size.width, phone.y+15, SCREEN_WIDTH-30-size.width-SW(20), size.height)];
	[_scorllView addSubview:phoneTF];
	phoneTF.textAlignment = NSTextAlignmentRight;
	phoneTF.textColor = [UIColor lightGrayColor];
	phoneTF.font = kUHSystemFontWithSize(15);
	phoneTF.tag = 31;
	phoneTF.delegate = self;
	
	
	//邮箱
	UILabel *email = [self.view viewWithTag:12];
	email.frame = CGRectMake(0, phone.y+phone.height+1, SCREEN_WIDTH, size.height+30);
	[_scorllView addSubview:email];
	UITextField *emailTF = [[UITextField alloc] initWithFrame:CGRectMake(30+size.width, email.y+15, SCREEN_WIDTH-30-size.width-SW(20), size.height)];
	[_scorllView addSubview:emailTF];
	emailTF.textAlignment = NSTextAlignmentRight;
	emailTF.textColor = [UIColor lightGrayColor];
	emailTF.font = kUHSystemFontWithSize(15);
	emailTF.tag = 32;
	emailTF.delegate = self;
	
	
	//留下一句话
	UILabel *sign = [self.view viewWithTag:13];
	sign.frame = CGRectMake(0, email.y+email.height+1, SCREEN_WIDTH, size.height+30);
	
	UITextView *signTV = [[UITextView alloc] init];
	[_scorllView addSubview:signTV];
	NSString *signStr = @"这个人很懒，什么都没有写。";
	//    if (signStr.length > 250) {
	//        signTV.text = [self.userInfo[@"intro"] substringFromIndex:250];
	//    }
	//    else
	signTV.text = signStr;
	signTV.textColor = [UIColor lightGrayColor];
	signTV.font = kUHSystemFontWithSize(14);
	signTV.delegate = self;
	//    signTV.adjustsFontForContentSizeCategory = YES;
	[signTV scrollRangeToVisible:NSMakeRange(0,1)];
	CGSize signSize = [signTV sizeThatFits:CGSizeMake(SCREEN_WIDTH-20-SW(20), MAXFLOAT)];
	signTV.frame = CGRectMake(0, sign.y+sign.height+1, SCREEN_WIDTH, 15+signSize.height);
	signTV.textContainerInset = UIEdgeInsetsMake(15, SW(20), 15, 20);//设置页边
	signTV.tag = 33;
	
	_pickerBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
	[self.view addSubview:_pickerBgView];
	_pickerBgView.backgroundColor = RGBA(0, 0, 0, 0.2);
	_pickerBgView.hidden = YES;
	
	//初始化mainPickView
	
	_categoryPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 2*SCREEN_HEIGHT, SCREEN_WIDTH, SH(3))];
	[self.view addSubview:_categoryPicker];
	_categoryPicker.delegate = self;
	_categoryPicker.dataSource = self;
	_categoryPicker.backgroundColor = UISeparatedColorRGB;
	_categoryPicker.showsSelectionIndicator = YES;
	_categoryPicker.hidden = YES;
	
	_salaryInfoArr = @[@"2000以下", @"2k-4k", @"4k-6k", @"6k-8k", @"8k-10k", @"10k-15k", @"15k-20k", @"20k-30k", @"30k-40k", @"40k-50k", @"5万以上"];
	_salaryPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 2*SCREEN_HEIGHT, SCREEN_WIDTH, SH(3))];
	[self.view addSubview:_salaryPicker];
	_salaryPicker.delegate = self;
	_salaryPicker.dataSource = self;
	_salaryPicker.backgroundColor = UISeparatedColorRGB;
	_salaryPicker.showsSelectionIndicator = YES;
	_salaryPicker.hidden = YES;
	
	
	_educationInfoArr = @[@"初中及以下", @"中专/中技", @"高中", @"大专", @"本科", @"硕士", @"博士"];
	_educationPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 2*SCREEN_HEIGHT, SCREEN_WIDTH, SH(3))];
	[self.view addSubview:_educationPicker];
	_educationPicker.delegate = self;
	_educationPicker.dataSource = self;
	_educationPicker.backgroundColor = UISeparatedColorRGB;
	_educationPicker.showsSelectionIndicator = YES;
	_educationPicker.hidden = YES;
	
	
	_workLifeInfoArr = @[@"应届生", @"1年以内", @"1-3年", @"3-5年", @"5-10年", @"10年以上"];
	_workLifePicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 2*SCREEN_HEIGHT, SCREEN_WIDTH, SH(3))];
	[self.view addSubview:_workLifePicker];
	_workLifePicker.delegate = self;
	_workLifePicker.dataSource = self;
	_workLifePicker.backgroundColor = UISeparatedColorRGB;
	_workLifePicker.showsSelectionIndicator = YES;
	_workLifePicker.hidden = YES;
	
	_pickerToolbgView = [[UIView alloc] initWithFrame:CGRectMake(0, 2*SCREEN_HEIGHT, SCREEN_WIDTH, 40)];
	[self.view addSubview:_pickerToolbgView];
	_pickerToolbgView.backgroundColor = UISeparatedColorRGB;
	
	NSArray *arr2 = @[@"取消", @"确定"];
	for (int i = 0; i < arr2.count; i++) {
		UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
		[_pickerToolbgView addSubview:btn];
		[btn setTitle:arr2[i] forState:UIControlStateNormal];
		[btn setTitleColor:kBlackColor forState:UIControlStateNormal];
		btn.titleLabel.font = kUHSystemFontWithSize(12);
		if (i==0) {
			btn.frame = CGRectMake(0, 0, 50, 40);
			[btn addTarget:self action:@selector(pickerRemove) forControlEvents:UIControlEventTouchUpInside];
		}
		else {
			btn.frame = CGRectMake(SCREEN_WIDTH-50, 0, 50, 40);
			[btn addTarget:self action:@selector(priceBtnText) forControlEvents:UIControlEventTouchUpInside];
		}
	}
	UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 39, SCREEN_WIDTH, 1)];
	[_pickerToolbgView addSubview:line];
	line.backgroundColor = kLightGrayColor;
	
	//保存按钮
	UIButton *saveBtn = [[UIButton alloc] initWithFrame:CGRectMake( 30, signTV.y+signTV.height+20,  SCREEN_WIDTH-30*2, 40)];
	saveBtn.layer.cornerRadius = saveBtn.height/4;
	[saveBtn setTitle:@"保存" forState:UIControlStateNormal];
	[saveBtn setBackgroundColor:UIMainColorRGB];
	[saveBtn addTarget:self action:@selector(completeAction:) forControlEvents:UIControlEventTouchUpInside];
	[_scorllView addSubview:saveBtn];
	
	_scorllView.contentSize = CGSizeMake(SCREEN_WIDTH, saveBtn.y+saveBtn.height+20);
	
}

- (UILabel *)createLabel:(UILabel *)label text:(NSString *)text {
	
	label.textColor = [UIColor grayColor];
	label.text = text;
	label.font = kUHSystemFontWithSize(15);
	label.backgroundColor = kWhiteColor;
	return label;
}

#pragma mark ==========UIPickerView==========
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView*)pickerView
{
	//    return 2; // 返回1表明该控件只包含1列
	
	if ([pickerView isEqual:_agePicker] || [pickerView isEqual:_salaryPicker]
		|| [pickerView isEqual:_educationPicker] || [pickerView isEqual:_workLifePicker]) {
		return 1;
	}
	else {
		return 2;
	}
}
//UIPickerViewDataSource中定义的方法，该方法的返回值决定该控件指定列包含多少个列表项
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
	// 由于该控件只包含一列，因此无须理会列序号参数component
	// 该方法返回books.count，表明books包含多少个元素，该控件就包含多少行
	//    return self.pickerArr.count;
	if ([pickerView isEqual:_agePicker]) {
		return self.ageArr.count;
	}
	else if([pickerView isEqual:_categoryPicker]){
		if (component == 0) {
			return self.jobCategoryInfoArr.count;
		}
		else {
			
			if (self.jobCategoryInfoArr.count) {
				JobCategoryInfo *model = self.jobCategoryInfoArr[[pickerView selectedRowInComponent:0]];
				NSArray *array = model.child;
				if (array != nil && ![array isKindOfClass:[NSNull class]] && array.count != 0 ) {
					return array.count;
				}
				else{
					return 0;
				}
			}
			else{
				return 0;
			}
		}
	}
	else if([pickerView isEqual:_salaryPicker]){
		return self.salaryInfoArr.count;
	}
	else if([pickerView isEqual:_educationPicker]){
		return self.educationInfoArr.count;
	}
	else if([pickerView isEqual:_workLifePicker]){
		return self.workLifeInfoArr.count;
	}
	else {
		return 0;
	}
}
// UIPickerViewDelegate中定义的方法，该方法返回的NSString将作为UIPickerView
// 中指定列和列表项的标题文本
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
	// 由于该控件只包含一列，因此无须理会列序号参数component
	// 该方法根据row参数返回books中的元素，row参数代表列表项的编号，
	// 因此该方法表示第几个列表项，就使用books中的第几个元素
	//    return [self.pickerArr objectAtIndex:row];
	if ([pickerView isEqual:_agePicker]) {
		return [self.ageArr objectAtIndex:row];
	}
	else if([pickerView isEqual:_categoryPicker]) {
		if (component == 0) {
			JobCategoryInfo *model = self.jobCategoryInfoArr[row];
			return model.title;
		} else {
			JobCategoryInfo *model = self.jobCategoryInfoArr[[pickerView selectedRowInComponent:0]];
			NSArray *array = model.child;
			if (array != nil && ![array isKindOfClass:[NSNull class]] && array.count != 0 && array.count >= row+1) {
				return [array[row] objectForKey:@"title"];
			}
			else {
				return @"";
			}
		}
	}
	else if([pickerView isEqual:_salaryPicker]) {
		return self.salaryInfoArr[row];
	}
	else if([pickerView isEqual:_educationPicker]) {
		return self.educationInfoArr[row];
	}
	else if([pickerView isEqual:_workLifePicker]) {
		return self.workLifeInfoArr[row];
	}
	else{
		return @"";
	}
}
// 当用户选中UIPickerViewDataSource中指定列和列表项时激发该方法
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
	//    [_priceSortedBtn setTitle:self.pickerArr[row] forState:UIControlStateNormal];
	//    self.pickerStr = self.pickerArr[row];
	if ([pickerView isEqual:_categoryPicker]) {
		
		[pickerView reloadComponent:1];
		[pickerView reloadComponent:0];
	}
}

- (void)priceBtnText {
	
	if(_categoryPicker.isHidden == NO) {
		JobCategoryInfo *parent = self.jobCategoryInfoArr[[_categoryPicker selectedRowInComponent:0]];
		NSArray *children = parent.child;
		if (children != nil && ![children isKindOfClass:[NSNull class]] && children.count != 0)
		{
			self.jobCategoryStr = children[[_categoryPicker selectedRowInComponent:1]][@"title"];
			self.selectedCategoryID = children[[_categoryPicker selectedRowInComponent:1]][@"id"];
			_jobCategoryTF.text = self.jobCategoryStr;
			NSLog(@"the selected jobID is %@", self.selectedCategoryID);
		}
		//如果没有子分类就用父级的信息
		else {
			self.jobCategoryStr = parent.title;
			self.selectedCategoryID = parent.cateId;
			_jobCategoryTF.text = self.jobCategoryStr;
			NSLog(@"the selected jobID is %@", self.selectedCategoryID);
		}
		
		[self pickerRemove];
	}
	else if(_salaryPicker.isHidden == NO)
	{
		UITextField *textField = (UITextField *)[self.view viewWithTag:27];
		textField.text = self.salaryInfoArr[[_salaryPicker selectedRowInComponent:0]];
		[self pickerRemove];
	}
	else if(_educationPicker.isHidden == NO)
	{
		UITextField *textField = [self.view viewWithTag:28];
		textField.text = self.educationInfoArr[[_educationPicker selectedRowInComponent:0]];
		[self pickerRemove];
	}
	else if(_workLifePicker.isHidden == NO)
	{
		UITextField *textField = [self.view viewWithTag:29];
		textField.text = self.workLifeInfoArr[[_workLifePicker selectedRowInComponent:0]];
		[self pickerRemove];
	}
	
}

- (void)pickerShow:(NSInteger)picker {
	[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
	if (picker == 1) {
		//_agePicker.hidden = NO;
	}
	else if(picker == 2){
		[self getCategory];
		_categoryPicker.hidden = NO;
		_pickerBgView.hidden = NO;
		[UIView animateWithDuration:0.33 animations:^{
			_pickerToolbgView.y = SH(3)*2-40;
			_categoryPicker.y = SH(3)*2;
		} completion:^(BOOL finished) {
		}];
	}
	else if(picker == 3){
		_salaryPicker.hidden = NO;
		_pickerBgView.hidden = NO;
		[UIView animateWithDuration:0.33 animations:^{
			_pickerToolbgView.y = SH(3)*2-40;
			_salaryPicker.y = SH(3)*2;
		} completion:^(BOOL finished) {
		}];
	}
	else if(picker == 4){
		_educationPicker.hidden = NO;
		_pickerBgView.hidden = NO;
		[UIView animateWithDuration:0.33 animations:^{
			_pickerToolbgView.y = SH(3)*2-40;
			_educationPicker.y = SH(3)*2;
		} completion:^(BOOL finished) {
		}];
	}
	else if(picker == 5){
		_workLifePicker.hidden = NO;
		_pickerBgView.hidden = NO;
		[UIView animateWithDuration:0.33 animations:^{
			_pickerToolbgView.y = SH(3)*2-40;
			_workLifePicker.y = SH(3)*2;
		} completion:^(BOOL finished) {
		}];
	}
}
- (void)pickerRemove {
	
	[UIView animateWithDuration:0.33 animations:^{
		_pickerToolbgView.y = 2*SCREEN_HEIGHT;
		_categoryPicker.y = 2*SCREEN_HEIGHT;
		_salaryPicker.y = 2*SCREEN_HEIGHT;
		_educationPicker.y = 2*SCREEN_HEIGHT;
		_workLifePicker.y = 2*SCREEN_HEIGHT;
		_agePicker.y = 2*SCREEN_HEIGHT;
	} completion:^(BOOL finished) {
		_pickerBgView.hidden = YES;
		_agePicker.hidden = YES;
		_categoryPicker.hidden = YES;
		_salaryPicker.hidden = YES;
		_educationPicker.hidden = YES;
		_workLifePicker.hidden = YES;
	}];
}

#pragma mark ==========响应方法==========
- (void)navLeftAction:(id)sender {
	if (self.isTeturn) {
		[self isReturn];
	}
	else
		[self dismissViewControllerAnimated:YES completion:nil];
}

- (void)isReturn {
	NSLog(@"++++++%d", self.isTeturn);
	
	if (self.isTeturn) {
		
		UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"是否放弃修改？" message:nil preferredStyle:UIAlertControllerStyleAlert];
		[alert addAction:[UIAlertAction actionWithTitle:@"返回上一层" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
			self.isTeturn = 0;
			[self dismissViewControllerAnimated:YES completion:nil];
		}]];
		[alert addAction:[UIAlertAction actionWithTitle:@"继续编辑" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
		}]];
		[self presentViewController:alert animated:YES completion:nil];
	}
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
	if (textField.tag == 32) {
		if (![self isValidEmail:textField.text]) {
			[LZCTools HUDMessage:@"请输入正确的邮箱" delay:1.0];
			textField.text = @"";
		}
	}
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
{
	self.isTeturn = 1;
	
	//删除的话string是@“”
	if ([string isEqualToString:@""]){
		return YES;
	}
	
	//string就是此时输入的那个字符textField就是此时正在输入的那个输入框返回YES就是可以改变输入框的值NO相反
	if ([string isEqualToString:@"\n"])  //按会车可以改变
	{
		return YES;
	}
	
	NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string]; //得到输入框的内容
	
	if ([self.view viewWithTag:22] == textField)  //判断是否时我们想要限定的那个输入框
	{
		if ([toBeString length] > 20) { //如果输入框内容大于20则弹出警告
			textField.text = [toBeString substringToIndex:20];
			[self presentViewController:[LZCTools alertMessage:@"名称不可以超过20字"] animated:YES completion:nil];
			return NO;
		}
	}
	if (textField.tag == 31) {
		if (textField.text.length >= 11) {
			return NO;
		}
		return [self validateNumber:string];
	}
	
	return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
	[textField resignFirstResponder];
	if (textField.text.length == 0) {

	}
	return YES;
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
	if ([text isEqualToString:@"\n"]){ //判断输入的字是否是回车，即按下return
		//在这里做你响应return键的代码
		[textView resignFirstResponder];
		return NO; //这里返回NO，就代表return键值失效，即页面上按下return，不会出现换行，如果为yes，则输入页面会换行
	}
	
	return YES;
}
- (void)textViewDidChange:(UITextView *)textView
{
	self.isTeturn = 1;
	
	if (textView.text.length > 30) {
		[self presentViewController:[LZCTools alertMessage:@"不可以超过30字"] animated:YES completion:nil];
		textView.text = [textView.text substringToIndex:30];
		[textView resignFirstResponder];
		return;
	}
	
	[textView flashScrollIndicators];   // 闪动滚动条
	
	//    static CGFloat maxHeight = 130.0f;
	static CGFloat maxHeight = 500.0f;
	CGRect frame = textView.frame;
	CGSize constraintSize = CGSizeMake(frame.size.width, MAXFLOAT);
	CGSize size = [textView sizeThatFits:constraintSize];
	if (size.height >= maxHeight)
	{
		size.height = maxHeight;
		textView.scrollEnabled = YES;   // 允许滚动
	}
	else
	{
		textView.scrollEnabled = NO;    // 不允许滚动，当textview的大小足以容纳它的text的时候，需要设置scrollEnabed为NO，否则会出现光标乱滚动的情况
	}
	textView.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, size.height);
	
	/*
	if ([textView isEqual:[self.view viewWithTag:16]]) {
		
		
		_scorllView.contentSize = CGSizeMake(SCREEN_WIDTH, textView.y+textView.height);
	}
	 */
}

- (BOOL)validateNumber:(NSString*)number {
	BOOL res = YES;
	NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
	int i = 0;
	while (i < number.length) {
		NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
		NSRange range = [string rangeOfCharacterFromSet:tmpSet];
		if (range.length == 0) {
			res = NO;
			break;
		}
		i++;
	}
	return res;
}

- (BOOL)isValidEmail:(NSString *)email {
	NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
	NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
	return [emailTest evaluateWithObject:email];
}

- (void)completeAction:(UIButton *)sender {
	NSLog(@"完成信息编辑");
	[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
	
	if (_isChangeImage) {
		// 上传图片如果尚未成功，就重新执行此方法 延时
		if (self.imgStr.length == 0) {
			[self performSelector:@selector(completeAction:) withObject:nil afterDelay:1.0f];
			return;
		}
	}
	UITextField *jobCategoryTF = (UITextField *)[self.view viewWithTag:26];
	UITextField *salaryTF = (UITextField *)[self.view viewWithTag:27];
	UITextField *educationTF = (UITextField *)[self.view viewWithTag:28];
	UITextField *workLifeTF = (UITextField *)[self.view viewWithTag:29];
	UITextField *phoneTF = (UITextField *)[self.view viewWithTag:31];
	UITextField *emailTF = (UITextField *)[self.view viewWithTag:32];
	
	NSArray *tfArr = @[jobCategoryTF, salaryTF, educationTF, workLifeTF, phoneTF, emailTF];
	
	for(UITextField *tf in tfArr)
	{
		if ([NSString isEmpty:tf.text]) {
			[self presentViewController:[LZCTools alertMessage:@"带*标识符的为必填项，请填写完成后再提交"] animated:YES completion:nil];
			return;
		}
	}
	
	UITextField *nameTF = (UITextField *)[self.view viewWithTag:22];
	UITextField *workDateTF = (UITextField *)[self.view viewWithTag:30];
	UITextField *districtTF = (UITextField *)[self.view viewWithTag:24];
	UITextView *descTF = (UITextView *)[self.view viewWithTag:33];
	
	
	NSDictionary *paramDict = @{
								@"title":jobCategoryTF.text,
								@"name":nameTF.text,
								@"desc":descTF.text,
								@"head_img":self.imgStr,
								@"sex":self.sexT,
								@"category_id":self.selectedCategoryID,
								@"salary":salaryTF.text,
								@"education":educationTF.text,
								@"mobile":phoneTF.text,
								@"email":emailTF.text,
								@"work_life":workLifeTF.text,
								@"work_date":self.workDateStr,
								@"district":districtTF.text,
								@"birth_date":self.birthdayStr,
								};
	
	// PUT /users 修改用户信息 nickname 用户昵称 intro 用户简介 face 头像图片地址
	[[NetworkTool sharedTool] requestWithName:@"创建新简历" URLString:APIPersonalAddResume parameters:paramDict method:@"POST" callBack:^(id responseObject) {
		NSString *resultState = responseObject[@"data"][@"status"];
		if ([resultState integerValue] == 1) {
			UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"创建成功" message:nil preferredStyle:UIAlertControllerStyleAlert];
			[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
				self.isTeturn = 0;
				[self dismissViewControllerAnimated:YES completion:nil];
			}]];
			[self presentViewController:alert animated:YES completion:nil];
		}
	}];
}

- (void)sexAction:(UIButton *)sender {
	NSLog(@"修改性别");
	
	self.isTeturn = 1;
	
	UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"修改性别" message:nil preferredStyle:UIAlertControllerStyleAlert];
	//    [alert addAction:[UIAlertAction actionWithTitle:@"保密" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
	//        [sender setTitle:@"保密" forState:UIControlStateNormal];
	//        self.sexT = @"0";
	//    }]];
	[alert addAction:[UIAlertAction actionWithTitle:@"男" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
		[sender setTitle:@"男" forState:UIControlStateNormal];
		self.sexT = @"1";
	}]];
	[alert addAction:[UIAlertAction actionWithTitle:@"女" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
		[sender setTitle:@"女" forState:UIControlStateNormal];
		self.sexT = @"2";
	}]];
	[self presentViewController:alert animated:YES completion:nil];
	
}
- (void)headPicAction:(UIButton *)sender {
	
	UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"修改个人头像" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
	
	[alert addAction:[UIAlertAction actionWithTitle:@"从相册中选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
		NSLog(@"从相册中选择");
		self.isTeturn = 1;
		self.picker.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;
		self.picker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:self.picker.sourceType];
		[self presentViewController:self.picker animated:YES completion:nil];
		
	}]];
	[alert addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
		NSLog(@"拍照");
		self.isTeturn = 1;
		self.picker.sourceType =  UIImagePickerControllerSourceTypeCamera;
		self.picker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:self.picker.sourceType];
		[self presentViewController:self.picker animated:YES completion:nil];
		
	}]];
	[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
		
	}]];
	[self presentViewController:alert animated:YES completion:nil];
	
}


#pragma mark ==========照相机相册功能==========
/**
 *  配置图片选择器
 */
-(void)createImgPicker {
	self.picker = [[UIImagePickerController alloc]init];
	self.picker.delegate = self;
	self.picker.allowsEditing = YES;
	self.picker.navigationBar.tintColor = [UIColor blackColor];
}

/**
 *  当用户选取完成后调用
 *
 *  @param picker 图片选择器对象
 *  @param info   返回用户所选择的媒体信息
 */
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
	
	NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
	
	// 判断选择的媒体类型是否为图片
	if ([mediaType isEqualToString:@"public.image"]) {
		
		if (picker.sourceType == UIImagePickerControllerSourceTypeCamera){
			
			//如果是 来自照相机的image，那么先保存
			UIImage* original_image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
			UIImageWriteToSavedPhotosAlbum(original_image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
			
		}
		
		//获得编辑过的图片
		UIImage *image = [[info objectForKey: @"UIImagePickerControllerEditedImage"] copy];
		
		[self updateCover:image];
		
		UIButton *imgBtn = [self.view viewWithTag:21];
		[imgBtn setImage:image forState:UIControlStateNormal];
		
		[self dismissViewControllerAnimated:YES completion:nil];
		
	}
}

/**
 *  将图片保存到iPhone本地相册
 *  UIImage *image            图片对象
 *  id completionTarget       响应方法对象
 *  SEL completionSelector    方法
 *  void *contextInfo
 */
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
	
	if (error == nil) {
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"照片已存入手机相册" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
		[alert show];
		
	}else{
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"照片保存失败" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
		[alert show];
	}
	
}
//如果这是一个modalViewController，需要dismiss 它发了个cancel消息，必须关闭它
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
	[self dismissViewControllerAnimated:YES completion:nil];
}


#pragma mark ==========网络请求==========
- (void)updateCover:(UIImage *)img {
	
	self.isChangeImage = 1;
	
	[MBProgressHUD showHUDAddedTo:self.view animated:YES];
	
	AFHTTPSessionManager *afn = [AFHTTPSessionManager manager];
	
	// 请求头
	[afn.requestSerializer setValue:[GetUserDefaule(Token) valueForKey:@"access_token"]forHTTPHeaderField:@"Authorization"];
	NSDictionary *dict = @{
						   @"file[]":@[]
						   };
	
	[afn POST:APIImages parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
		// formData: 专门用于拼接需要上传的数据,在此位置生成一个要上传的数据体
		// 这里的_photoArr是你存放图片的数组
		NSData *imageData = UIImageJPEGRepresentation(img, 0.8);
		
		// 在网络开发中，上传文件时，是文件不允许被覆盖，文件重名
		// 要解决此问题，
		// 可以在上传时使用当前的系统事件作为文件名
		NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
		// 设置时间格式
		[formatter setDateFormat:@"yyyyMMddHHmmss"];
		NSString *dateString = [formatter stringFromDate:[NSDate date]];
		NSString *fileName = [NSString  stringWithFormat:@"%@.jpg", dateString];
		/*
		 *该方法的参数
		 1. appendPartWithFileData：要上传的照片[二进制流]
		 2. name：对应网站上[upload.php中]处理文件的字段（比如upload）
		 3. fileName：要保存在服务器上的文件名
		 4. mimeType：上传的文件的类型
		 */
		[formData appendPartWithFileData:imageData name:@"pic[]" fileName:fileName mimeType:@"image/jpeg"]; //
		
	} progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
		id obj = [JWT decodeMessage:responseObject[@"token"]].secret(JWTSecret).algorithmName(@"HS256").decode;
		//        return [obj valueForKey:@"payload"];
		NSArray *imgArr = [[[obj valueForKey:@"payload"] valueForKey:@"data"] valueForKey:@"images"];
		NSLog(@"上传图片 success = %@", imgArr);
		self.imgStr = imgArr[0];
		
		[MBProgressHUD hideHUDForView:self.view animated:YES];
		
	} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
		NSLog(@"上传图片 failure = %@", error);
		[self presentViewController:[LZCTools AFNErrorAlert:error] animated:YES completion:nil];
		[MBProgressHUD hideHUDForView:self.view animated:YES];
	}];
}

- (NSMutableArray *)ageArr {
	if (_ageArr == nil) {
		_ageArr = [[NSMutableArray alloc] init];
		for (int i = 1; i < 101; i++) {
			[_ageArr addObject:[NSString stringWithFormat:@"%d", i]];
		}
	}
	return _ageArr;
}

- (NSMutableArray *)jobCategoryInfoArr
{
	if (!_jobCategoryInfoArr) {
		_jobCategoryInfoArr = [[NSMutableArray alloc] init];
	}
	return _jobCategoryInfoArr;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
